package com.huawei.hms.framework.network.restclient.hianalytics;

import com.huawei.hms.framework.common.Logger;
import com.huawei.hms.framework.network.util.ContextUtil;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class FileRecordManager {
    private static final String FILE_NAME = "data.txt";
    private static final String LINE_SEPARATOR = "line.separator";
    private static final String TAG = "FileRecordManager";
    private static final FileRecordManager ourInstance = new FileRecordManager();
    private static final String savaPath = (ContextUtil.getContext().getExternalCacheDir() + File.separator + FILE_NAME);
    private ExecutorService executorService;

    private FileRecordManager() {
        this.executorService = null;
        this.executorService = Executors.newSingleThreadExecutor();
    }

    public static FileRecordManager getInstance() {
        return ourInstance;
    }

    public void saveToLocalFile(final String str) {
        Logger.v(TAG, "come into the savaToLocalFile! %s", new Object[]{savaPath});
        this.executorService.execute(new Runnable() {
            /* JADX WARNING: inconsistent code. */
            /* Code decompiled incorrectly, please refer to instructions dump. */
            public void run() {
                /*
                r5 = this;
                r0 = 0;
                r1 = com.huawei.hms.framework.network.restclient.hianalytics.FileRecordManager.savaPath;	 Catch:{ FileNotFoundException -> 0x004d, IOException -> 0x0064, all -> 0x007b }
                r2 = "rwd";
                r0 = com.huawei.hms.framework.common.CreateFileUtil.newRandomAccessFile(r1, r2);	 Catch:{ FileNotFoundException -> 0x004d, IOException -> 0x0064, all -> 0x007b }
                r2 = r0.length();	 Catch:{ FileNotFoundException -> 0x004d, IOException -> 0x0064 }
                r0.seek(r2);	 Catch:{ FileNotFoundException -> 0x004d, IOException -> 0x0064 }
                r1 = com.huawei.hms.framework.network.restclient.hianalytics.FileRecordManager.this;	 Catch:{ FileNotFoundException -> 0x004d, IOException -> 0x0064 }
                r1 = r1.getDate();	 Catch:{ FileNotFoundException -> 0x004d, IOException -> 0x0064 }
                r2 = "line.separator";
                r2 = java.lang.System.getProperty(r2);	 Catch:{ FileNotFoundException -> 0x004d, IOException -> 0x0064 }
                r3 = new java.lang.StringBuilder;	 Catch:{ FileNotFoundException -> 0x004d, IOException -> 0x0064 }
                r3.<init>();	 Catch:{ FileNotFoundException -> 0x004d, IOException -> 0x0064 }
                r1 = r3.append(r1);	 Catch:{ FileNotFoundException -> 0x004d, IOException -> 0x0064 }
                r3 = r6;	 Catch:{ FileNotFoundException -> 0x004d, IOException -> 0x0064 }
                r1 = r1.append(r3);	 Catch:{ FileNotFoundException -> 0x004d, IOException -> 0x0064 }
                r1 = r1.append(r2);	 Catch:{ FileNotFoundException -> 0x004d, IOException -> 0x0064 }
                r1 = r1.toString();	 Catch:{ FileNotFoundException -> 0x004d, IOException -> 0x0064 }
                r2 = "UTF-8";
                r1 = r1.getBytes(r2);	 Catch:{ FileNotFoundException -> 0x004d, IOException -> 0x0064 }
                r0.write(r1);	 Catch:{ FileNotFoundException -> 0x004d, IOException -> 0x0064 }
                if (r0 == 0) goto L_0x0043;
            L_0x0040:
                r0.close();	 Catch:{ IOException -> 0x0044 }
            L_0x0043:
                return;
            L_0x0044:
                r0 = move-exception;
                r0 = "FileRecordManager";
                r1 = "the randomAccessFile isn't colsed successfully!";
                com.huawei.hms.framework.common.Logger.w(r0, r1);
                goto L_0x0043;
            L_0x004d:
                r1 = move-exception;
                r1 = "FileRecordManager";
                r2 = "the file is not found";
                com.huawei.hms.framework.common.Logger.w(r1, r2);	 Catch:{ all -> 0x008e }
                if (r0 == 0) goto L_0x0043;
            L_0x0057:
                r0.close();	 Catch:{ IOException -> 0x005b }
                goto L_0x0043;
            L_0x005b:
                r0 = move-exception;
                r0 = "FileRecordManager";
                r1 = "the randomAccessFile isn't colsed successfully!";
                com.huawei.hms.framework.common.Logger.w(r0, r1);
                goto L_0x0043;
            L_0x0064:
                r1 = move-exception;
                r1 = "FileRecordManager";
                r2 = "the file write fail!";
                com.huawei.hms.framework.common.Logger.w(r1, r2);	 Catch:{ all -> 0x008e }
                if (r0 == 0) goto L_0x0043;
            L_0x006e:
                r0.close();	 Catch:{ IOException -> 0x0072 }
                goto L_0x0043;
            L_0x0072:
                r0 = move-exception;
                r0 = "FileRecordManager";
                r1 = "the randomAccessFile isn't colsed successfully!";
                com.huawei.hms.framework.common.Logger.w(r0, r1);
                goto L_0x0043;
            L_0x007b:
                r1 = move-exception;
                r4 = r1;
                r1 = r0;
                r0 = r4;
            L_0x007f:
                if (r1 == 0) goto L_0x0084;
            L_0x0081:
                r1.close();	 Catch:{ IOException -> 0x0085 }
            L_0x0084:
                throw r0;
            L_0x0085:
                r1 = move-exception;
                r1 = "FileRecordManager";
                r2 = "the randomAccessFile isn't colsed successfully!";
                com.huawei.hms.framework.common.Logger.w(r1, r2);
                goto L_0x0084;
            L_0x008e:
                r1 = move-exception;
                r4 = r1;
                r1 = r0;
                r0 = r4;
                goto L_0x007f;
                */
                throw new UnsupportedOperationException("Method not decompiled: com.huawei.hms.framework.network.restclient.hianalytics.FileRecordManager.1.run():void");
            }
        });
    }

    public String getDate() {
        String str = "";
        Logger.v(TAG, "the time is : %s", new Object[]{new SimpleDateFormat("yyyy-MM-dd&&HH:mm:ss:SSSS", Locale.ENGLISH).format(new Date())});
        return new SimpleDateFormat("yyyy-MM-dd&&HH:mm:ss:SSSS", Locale.ENGLISH).format(new Date());
    }
}
